LLVM_CONFIG=llvm-config-14
CXX=c++

LDFLAGS+=$(shell $(LLVM_CONFIG) --ldflags)
# COMMON_FLAGS=-Wall -Wextra
COMMON_FLAGS=
CXXFLAGS+=$(COMMON_FLAGS) $(shell $(LLVM_CONFIG) --cxxflags) -fno-rtti -fPIC
CPPFLAGS+=$(shell $(LLVM_CONFIG) --cppflags) -g -I$(SRC_DIR)
CLANGLIBS=\
  -Wl,--start-group\
  -lclang\
  -lclangFrontend\
  -lclangDriver\
  -lclangSerialization\
  -lclangParse\
  -lclangSema\
  -lclangAnalysis\
  -lclangEdit\
  -lclangAST\
  -lclangLex\
  -lclangBasic \
  -lclangTooling \
  -Wl,--end-group

LLVMLIBS=$(shell $(LLVM_CONFIG) --libs)
SYSTEMLIBS=$(shell $(LLVM_CONFIG) --system-libs)

SRC=$(wildcard *.cpp)
OBJ=$(patsubst %.cpp, %.so, $(SRC))

TEST=-fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -fno-common -Woverloaded-virtual -fno-strict-aliasing -Wl,-z,nodelete

TEST1=-fPIC -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -fno-common -Woverloaded-virtual -fno-strict-aliasing -g  -Wl,-z,nodelete 

.PHONY:all clean
all: $(OBJ)
# ctest: find_class_decls ast_traversal diagnostics_example
# cpptest: front_end

%.so:%.cpp
	@echo Compiling $*.cpp
	$(CXX) $< $(CPPFLAGS) $(CXXFLAGS) -o $@ -shared -Wl,-O1 ${TEST1} $(LDFLAGS) $(CLANGLIBS) $(LLVMLIBS)

clean:
	rm -rf $(OBJ)
